package org.breathe.command.impl.rdb;

import org.breathe.command.Command;
import org.breathe.command.CommandType;
import org.breathe.protocal.Resp;
import org.breathe.protocal.decode.Errors;
import org.breathe.protocal.decode.SimpleString;
import org.breathe.server.core.RedisCore;

/**
 * @author: breathe
 * @createTime: 2025-06-08
 */
public class Bgsave implements Command {
    private RedisCore redisCore;
    public Bgsave(RedisCore redisCore) {
        this.redisCore = redisCore;
    }
    @Override
    public CommandType getType() {
        return CommandType.BGSAVE;
    }

    @Override
    public void setContext(Resp[] array) {

    }

    @Override
    public Resp handle() {
        Boolean result = redisCore.getServer().getRdbManager().saveRdb();
        if (result) {
            return new SimpleString("OK");
        }
        return new Errors("BGSAVE run error");
    }

    @Override
    public boolean writeCommand() {
        return false;
    }
}
